package tree;
import java.util.*;
public class Ex226 {
    class Solution {
        public TreeNode invertTree(TreeNode root) {
            if (root == null) return root;
            TreeNode cur = root;
            Queue<TreeNode> queue = new LinkedList<>();
            queue.offer(cur);
            while (!queue.isEmpty()) {
                cur = queue.poll();
                TreeNode left = cur.left, right = cur.right, temp = left;
                left = right;
                right = temp;
                if (left != null) queue.offer(left);
                if (right != null) queue.offer(right);
            }
            return root;
        }
    }
}
